<?php
/**
 *
 * @author Gonzalez Federico, Viera Leonel
 * @package Protoweb
 * @subpackage model
 */
class Template extends PwModel 
{

    public $name;
    public $template;

    public static function getAll()
    {
        // get CodeIngiter instace
        $CI =& get_instance();

        // get core actions template path
        $usrTemplates = scandir($CI->config->item('usr_action_tpl_path'));

        // remove '.' and '..' entries and reconstruct array index
        $usrTemplates = array_diff($usrTemplates, array('.','..'));
        $usrTemplates = array_values($usrTemplates);

        // build templates array
        $templatesArray = array();
        foreach ($usrTemplates as $templateName) {
            $templateObj = new Template(basename($templateName,'.tpl'));
            array_push($templatesArray, $templateObj);
        }
        
        return $templatesArray;
    }

    public function getFilePath()
    {
        // get CodeIngiter instace
        $CI =& get_instance();

        return $CI->config->item('usr_action_tpl_path') . $this->name . '.tpl';   
    }

    public function __construct($slug)
    {
        // get CodeIngiter instace
        $CI =& get_instance();

        $template = file_get_contents($CI->config->item('usr_action_tpl_path') . $slug . '.tpl');

        if ($template) {
            $this->name = $slug;
            $this->template = $template;
        }
        else {
            return null;
        }
    }

} // Class Template

/* End of file template.php */
/* Location: ./application/models/template.php */